<template>
    <div>
        <el-table max-height="510px" row-key="id" default-expand-all :tree-props="{ children: 'children' }" :data="cateList" border
            style="width: 100%">
            <el-table-column prop="pid" label="分类编号" width="180">
            </el-table-column>
            <el-table-column prop="catename" label="分类名称" width="180">
            </el-table-column>
            <el-table-column label="图片" width="180">
                <template slot-scope="item">
                    <div>
                        <img class="img" v-if="item.row.img" :src="$img+item.row.img" alt="">
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="状态" prop="status">
                <template slot-scope="item">
                    <div>
                        {{ item.row.status == 1 ? '正常' : '禁用' }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button size="mini" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="mini" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>

<script>
// 辅助性函数
import { mapGetters,mapActions } from 'vuex'
// 引入接口
import { cateDel } from '../../request/api'
export default {
    data() {
        return {

        };
    },
    computed: {
        ...mapGetters({
            cateList: 'cate/getCateList'
        })
    },
    mounted(){
        this.cateListAction()
    },
    methods: {
        ...mapActions({
            cateListAction:'cate/changeCateAction'
        }),
        edit(id) {
            this.$emit('edit',id)
        },
        // 删除事件
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 调用删除接口
                cateDel({
                    id
                }).then(res=>{
                    console.log(res,'删除');
                    this.$message.success(res.msg)
                    // 重新调用列表
                    this.cateListAction()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    }
};
</script>

<style  lang="less" scoped>
.img{
    width: 150px;
    height: 150px;
}
</style>
